from rest_framework import serializers
from .models import *


# 基于Serializer 序列化器
class StaffSerializer(serializers.Serializer):
    SEX_CHOICE = (
        (1, "男"),
        (2, "女")
    )
    # 要序列化哪些字段，需要自己写出来
    name = serializers.CharField(label="姓名", max_length=30)
    sex = serializers.ChoiceField(default=1, choices=SEX_CHOICE)
    phone = serializers.CharField(label="手机号", max_length=11)
    email = serializers.CharField(label="邮箱", max_length=60)

    dep = serializers.PrimaryKeyRelatedField(queryset=Dep.objects.all())
    duty = serializers.PrimaryKeyRelatedField(queryset=Duty.objects.all())


# 基于ModelSerializer 的序列化器
class StaffModelSerializer(serializers.ModelSerializer):
    # 自动生成序列化的字段
    class Meta:
        model = Staff  # 要序列化的模型类
        fields = "__all__"   # 要序列化哪些字段






